package scream.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Collection;

import scream.negocio.SeguridadNegocioRepresentante;
import scream.modelo.Representante;
import scream.excepcion.DAOExcepcion;

/**
 * Servlet implementation class Repre_Buscar_Servlet
 */
@WebServlet("/Repre_Buscar_Servlet")
public class Repre_Buscar_Servlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Repre_Buscar_Servlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		
		
		SeguridadNegocioRepresentante neg = new SeguridadNegocioRepresentante();
		
		String Cod_Cliente = request.getParameter("txt_cod_cli");
		
		
		
		System.out.print(Cod_Cliente);
		
		try {

			Collection<Representante> lista = neg
					.Buscar_Repre_x_Cliente(Cod_Cliente);

			System.out.print(lista.size());
			
			
			
			request.setAttribute("vRepres", lista);
			RequestDispatcher rd = request
					.getRequestDispatcher("ListarRepre.jsp");
			
			rd.forward(request, response);
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}
}
